package com.example.itshome.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.example.itshome.R;
import com.example.itshome.impl.ViewOutlineProviderImpl;
import com.example.itshome.entity.RescueStationEntity;

import java.util.List;

public class RescuePageRecycleViewAdapter extends RecyclerView.Adapter<RescuePageRecycleViewAdapter.HelpPageViewHolder> {
    private final List<RescueStationEntity> mData;
    private final Context context;

    public RescuePageRecycleViewAdapter(Context context, List<RescueStationEntity> list){mData=list;this.context=context;}

    @NonNull
    @Override
    public HelpPageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=View.inflate(context,R.layout.recycle_help_page_item,null);
        view.setOutlineProvider(new ViewOutlineProviderImpl(20));
        view.setClipToOutline(true);
        HelpPageViewHolder viewHolder= new HelpPageViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull HelpPageViewHolder holder, int position) {
        RescueStationEntity entity=mData.get(position);
        holder.topicTextView.setText(entity.topic);
        holder.phoneNumberTextView.setText(entity.phoneNumber);
        Glide.with(context).load(entity.picture).placeholder(R.drawable.sample_picture).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    static class HelpPageViewHolder extends RecyclerView.ViewHolder {

        private final ImageView imageView;
        private final TextView topicTextView;
        private final TextView phoneNumberTextView;
        public HelpPageViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.imv_recycle_help_page_image);
            topicTextView=itemView.findViewById(R.id.txv_recycle_help_topic);
            phoneNumberTextView=itemView.findViewById(R.id.txv_recycle_help_phone_number);
        }
    }
}
